#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:runserver.py.py
# author:吴凯博
# datetime:2022/5/1 15:16
# software: PyCharm
"""
this is function description
"""
from flask import Flask, jsonify

from config.settings import Settings
from utils.monitor import Monitor


app = Flask(__name__)
monitor = Monitor()


@app.route('/data', methods=['GET'])
def get_data():
    """
    获取数据，数据结构见utils/monitor.py中的Monitor.get_data()的注释
    :return:
    """
    return jsonify(code='200', message='SUCCESS', data=monitor.get_data())


@app.route('/data', mehtods=['POST'])
def record_data():
    """
    记录一次当前时刻的数据并返回，数据结构见utils/monitor.py中的Monitor.get_data()的注释
    :return:
    """
    return jsonify(code='200', message='SUCCESS', data=monitor.record_data())


@app.route('/data', methods=['DELETE'])
def init_data():
    """
    初始化数据，在每次开始监控前都要调用一次
    :return:
    """
    monitor.init_data()
    return jsonify(code='200', message='SUCCESS')


if __name__ == '__main__':
    app.run(port=Settings.SERVER_PORT)
